package structure;
import java.util.*;

public class Test6 {
    public static void main(String[] args) {

    }
    //力扣155.最小栈
    class MinStack {
        Stack<Integer> stack1;
        Stack<Integer> stack2;
        int n = Integer.MAX_VALUE;
        public MinStack() {
            stack1 = new Stack<>();
            stack2 = new Stack<>();
        }

        public void push(int node) {
            if (node < n) {
                n = node;
            }
            stack2.push(n);
            stack1.push(node);
        }

        public void pop() {
            stack1.pop();
            stack2.pop();
            if(!stack2.isEmpty() && stack2.peek() >= n){
                n = stack2.peek();
            }
            if(stack2.isEmpty()){
                n = Integer.MAX_VALUE;
            }
        }

        public int top() {
            return stack1.peek();
        }

        public int getMin() {
            return stack2.peek();
        }
    }
    //豆包1.找单独的数(异或解法)
    public static int solution(int[] cards) {
        // Edit your code here
        int num = 0;
        for(int i = 0;i < cards.length;i++){
            num ^= cards[i];
        }
        return num;
    }
    //力扣70. 爬楼梯
    public static int climbStairs(int num){
        if(num == 0){
            return 0;
        }
        if(num == 1){
            return 1;
        }
        if(num == 2){
            return 2;
        }
        int a = 1;
        int b = 2;
        int temp = 0;
        for(int i = 3;i <= num;i++){
            temp = a + b;
            a = b;
            b = temp;
        }
        return temp;
    }
    //力扣1768. 交替合并字符串
    public static String mergeAlternately(String word1, String word2) {
        StringBuilder sb = new StringBuilder();
        char[] str1 = word1.toCharArray();
        char[] str2 = word2.toCharArray();
        int len1 = str1.length;
        int len2 = str2.length;
        int n = 0;
        int n1 = 0;
        int n2 = 0;
        while(len1 > n1 && len2 > n2){
            if(n % 2 == 0){
                sb.append(str1[n1]);
                n1++;
            }else {
                sb.append(str2[n2]);
                n2++;
            }
            n++;
        }
        if(n1 == len1 && n2 != len2){
            sb.append(word2.substring(n2));
        }
        if(n1 != len1 && n2 == len2){
            sb.append(word1.substring(n1));
        }
        return sb.toString();
    }
}
